﻿using System;
using System.Windows.Forms;
using QuanLyTuyenSinh.PresentationLayer;
using QuanLyTuyenSinh.PresentationLayer.Components;

namespace QuanLyTuyenSinh.Base
{
    public partial class frmMain : DevComponents.DotNetBar.Office2007RibbonForm
    {
        public frmMain()
        {
            InitializeComponent();
        }

        #region Base

        private bool CheckExistForm(string name)
        {
            bool check = false;
            foreach (Form frm in MdiChildren)
            {
                if (frm.Name == name)
                {
                    check = true;
                    break;
                }
            }
            return check;
        }

        private void ActiveChildForm(string name)
        {
            foreach (Form frm in MdiChildren)
            {
                if (frm.Name == name)
                {
                    frm.Activate();
                    break;
                }
            }
        }

        #endregion
          

        #region Cập nhật danh mục

        private void CmdThisinhClick(object sender, EventArgs e)
        {
            if (!CheckExistForm(typeof(frmThiSinh).Name))
            {
                var frm = new frmThiSinh { Name = typeof(frmThiSinh).Name };
                frm.MdiParent = this;
                frm.Show();
            }
            else
                ActiveChildForm(typeof(frmThiSinh).Name);
           
        }
        private void BtnEthincClick(object sender, EventArgs e)
        {
            if (!CheckExistForm(typeof(frmEthnic).Name))
            {
                var frm = new frmEthnic { Name = typeof(frmEthnic).Name };
                frm.MdiParent = this;
                frm.Show();
            }
            else
                ActiveChildForm(typeof(frmEthnic).Name);
        }

        private void CmdTruongThptClick(object sender, EventArgs e)
        {
            if (!CheckExistForm(typeof (frmHighSchool).Name))
            {
                var frm = new frmHighSchool {Name = typeof (frmHighSchool).Name};
                frm.MdiParent = this;
                frm.Show();
            }
            else
                ActiveChildForm(typeof (frmHighSchool).Name);
        }

        private void CmdTruongDhClick(object sender, EventArgs e)
        {
            if (!CheckExistForm(typeof (frmUniversity).Name))
            {
                var frm = new frmUniversity {Name = typeof (frmUniversity).Name};
                frm.MdiParent = this;
                frm.Show();
            }
            else
                ActiveChildForm(typeof (frmUniversity).Name);
        }

        private void CmdNganhhocClick(object sender, EventArgs e)
        {
            if (!CheckExistForm(typeof (frmStudy).Name))
            {
                var frm = new frmStudy {Name = typeof (frmStudy).Name};
                frm.MdiParent = this;
                frm.Show();
            }
            else
                ActiveChildForm(typeof (frmStudy).Name);
        }

        private void CmdDoituongClick(object sender, EventArgs e)
        {
            if (!CheckExistForm(typeof (frmPriority).Name))
            {
                var frm = new frmPriority {Name = typeof (frmPriority).Name};
                frm.MdiParent = this;
                frm.Show();
            }
            else
                ActiveChildForm(typeof (frmPriority).Name);
        }

        private void CmdKhuvucClick(object sender, EventArgs e)
        {
            if (!CheckExistForm(typeof (frmZone).Name))
            {
                var frm = new frmZone {Name = typeof (frmZone).Name};
                frm.MdiParent = this;
                frm.Show();
            }
            else
                ActiveChildForm(typeof (frmZone).Name);
        }

        private void CmdDsTinhClick(object sender, EventArgs e)
        {
            if (!CheckExistForm(typeof (frmProvince).Name))
            {
                var frm = new frmProvince {Name = typeof (frmProvince).Name};
                frm.MdiParent = this;
                frm.Show();
            }
            else
                ActiveChildForm(typeof (frmProvince).Name);
        }

        private void CmdHuyenClick(object sender, EventArgs e)
        {
            if (!CheckExistForm(typeof (frmDistrict).Name))
            {
                var frm = new frmDistrict {Name = typeof (frmDistrict).Name};
                frm.MdiParent = this;
                frm.Show();
            }
            else
                ActiveChildForm(typeof (frmDistrict).Name);
        }

        #endregion


        private void CmdDanhSbdClick(object sender, EventArgs e)
        {
            var frm = new frmDanhSBD();
            frm.Visible = false;
            Hide();
            frm.ShowDialog();
        }

        private void CmdPhanphongClick(object sender, EventArgs e)
        {
            var frm = new frmPhanphong();
            frm.Visible = false;
            Hide();
            frm.ShowDialog();
        }

        private void CmdDanhphachClick(object sender, EventArgs e)
        {
            var frm = new frmDanhphach();
            frm.Visible = false;
            Hide();
            frm.ShowDialog();
        }

        private void CmdDontuiClick(object sender, EventArgs e)
        {
            var frm = new frmDontui();
            frm.Visible = false;
            Hide();
            frm.ShowDialog();
        }

        private void CmdNhapdiemClick(object sender, EventArgs e)
        {
            var frm = new frmNhapdiem();
            frm.Visible = false;
            Hide();
            frm.ShowDialog();
        }

        private void CmdKhopphachClick(object sender, EventArgs e)
        {
            var frm = new frmKhopphach();
            frm.Visible = false;
            Hide();
            frm.ShowDialog();
        }

     private void CmdReportDstsdkClick(object sender, EventArgs e)
        {
            //ReportDSTSDK frm = new ReportDSTSDK();
            //frm.Visible = false;
            //this.Hide();
            //frm.ShowDialog();
        }

        private void CmdReportDsPhongThiClick(object sender, EventArgs e)
        {
            //ReportDSPhongThi frm = new ReportDSPhongThi();
            //frm.Visible = false;
            //this.Hide();
            //frm.ShowDialog();
        }

        private void CmdPhieuBdtClick(object sender, EventArgs e)
        {
            //ReportPhieuBDT frm = new ReportPhieuBDT();
            //frm.Visible = false;
            //this.Hide();
            //frm.ShowDialog();
        }

        private void CmdSbdPhachClick(object sender, EventArgs e)
        {
            //ReportSBDPhach frm = new ReportSBDPhach();
            //frm.Visible = false;
            //this.Hide();
            //frm.ShowDialog();
        }

        private void CmdPhachDiemClick(object sender, EventArgs e)
        {
            //frmPhach frm = new frmPhach();
            //frm.Visible = false;
            //this.Hide();
            //frm.ShowDialog();
        }

        private void CmdSbdDiemClick(object sender, EventArgs e)
        {
            //frmSBDDiem frm = new frmSBDDiem();
            //frm.Visible = false;
            //this.Hide();
            //frm.ShowDialog();
        }

        private void IcoThoatClick(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void TimerGioHtTick(object sender, EventArgs e)
        {
            toolStripStatusLabel2.Text = DateTime.Now.ToShortTimeString();
        }

        private void CmdDiemchuanClick(object sender, EventArgs e)
        {
            var frm = new frmDiemchuan();
            frm.Visible = false;
            Hide();
            frm.ShowDialog();
        }

        private void CmdPhieubaoNhClick(object sender, EventArgs e)
        {
            //ReportPhieubaoNH frm = new ReportPhieubaoNH();
            //frm.Visible = false;
            //this.Hide();
            //frm.ShowDialog();
        }


        private void CmdPhieubaodiemClick(object sender, EventArgs e)
        {
            //ReportPhieubaoDiem frm = new ReportPhieubaoDiem();
            //frm.Visible = false;
            //this.Hide();
            //frm.ShowDialog();
        }

        private void CmdDsttNganhClick(object sender, EventArgs e)
        {
            //ReportDSTTNganh frm = new ReportDSTTNganh();
            //frm.Visible = false;
            //this.Hide();
            //frm.ShowDialog();
        }

        private void CmdDsttKhoiClick(object sender, EventArgs e)
        {
            //    ReportDSTTKhoi frm = new ReportDSTTKhoi();
            //    frm.Visible = false;
            //    this.Hide();
            //    frm.ShowDialog();
            //}
        }
      private void FrmMainLoad(object sender, EventArgs e)
        {
          Screen scr = Screen.PrimaryScreen;
          this.Left = (scr.WorkingArea.Width - this.Width)/2;
          this.Top = (scr.WorkingArea.Height - this.Height)/2;
        }

      private void BtnSearchClick(object sender, EventArgs e)
      {
          if (!CheckExistForm(typeof(frmTKSBD).Name))
          {
              var frm = new frmTKSBD { Name = typeof(frmTKSBD).Name };
              frm.MdiParent = this;
              frm.Show();
          }
          else
              ActiveChildForm(typeof(frmTKSBD).Name);
      }

     
    }
}